{extend name="base/base" /}
{block name="style"}
<style type="text/css">
.layui-table-cell{
     height: auto!important;
     white-space: normal;
}
</style>
{/block}
{block name="content"}
  <div class="layui-form-item layui-form-pane">
    <div class="layui-inline">
        <div class="demoTable">
          <button class="layui-btn layui-btn-normal" onclick="add()">新增</button>
        </div>
      </div>
  <table id="table" lay-filter="table"></table> 
</div>
  <script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  </script>
{/block}
{block name="script"}
<script>
layui.use(['table', 'laydate'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  table.render({
    elem: '#table'
    ,height: 'full-200'
    ,url: '/admin/coin/outList/' //数据接口
    ,limit:20
    ,page: true //开启分页
    ,id:'reload'
    ,cols: [[ //表头
      {field:'wallet', title: '钱包', width: 150}
      ,{field:'coin', title: '币种', width: 150}
      ,{field:'min_amount', title: '最低提币数量', width: 150}
      ,{field:'max_amount', title: '最大提币数量', width: 150}
      ,{field:'day_num', title: '日提币数量', width: 150}
      ,{field:'fee_type', title: '手续费类型', width: 200,templet: function(d){
        if(d.fee_type == 1){
          return '<span>按比例</span>'
        } else if (d.fee_type == 2) {
          return '<span>按个数</span>'
        }
      }}
      ,{field:'fee', title: '手续费', width: 150}
      ,{title:'操作', toolbar: '#barDemo', width:150}
    ]]
  }); 

  //监听工具条
  table.on('tool(table)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('确定删除？', function(index){
        $.ajax({
          url:"{:url('admin/coin/outDel')}?id="+data.id,
          type:'GET',
          success:function(ret){
            if(ret.code == 0) {
              layer.msg('删除成功');
              obj.del();
            } else {
              layer.msg('删除失败');
            }
          }
        });
      });
    }   
   //编辑
    if(obj.event === 'edit'){
      layer.open({
        type: 2 ,
        title: '编辑配置',   //标题
        area: ['500px', '500px'],   //宽高
        shade: 0.4,   //遮罩透明度
        content: '/admin/coin/outEdit?id='+data.id,//支持获取DOM元素
        // end:function(){
        //   $(".layui-laypage-btn")[0].click();
        // }
        });
    }
  });
});
function add(){
  layer.open({
        type: 2 ,
        title: '添加配置',   //标题
        area: ['500px', '500px'],   //宽高
        shade: 0.4,   //遮罩透明度
        content: '/admin/coin/outEdit'
        // end:function(){
        //   $(".layui-laypage-btn")[0].click();
        // }
        });
}
</script>
{/block}
